﻿/*
创建人：zhangrj
日期：2022-09-27
描述：质量提起页面js
*/
var page = {
    url: getRootPath() + "/Ashx/ContainerQualityCollectHandler.ashx", //后台处理url,
    init: function () {
        page.bind();
        page.initData();
    },
    //绑定事件
    bind: function () {
        //确认
        $("#btnSure").on("click", function () {
            clearMessage();
            page.saveData();
        });
        //关闭
        $("#btnClose").on("click", function () {
            window.close();
        });
    },
    //初始化页面数据
    initData: function () {
        //        var containerId = getParam("ContainerID");
        //        var workflowStepID = getParam("WorkflowStepID");
        page.post(page.url, { action: "GetInitPageData" }, true, function (res) {
            if (!res.Result) {
                displayMessage(res.Message, false);
                return;
            }
            var datas = res.DBDataSet;
            $('#SpecForm').form('load', datas.dtSpec[0]);
            $('#DealForm').form('load', datas.productDt[0]);
            $('#ContainerNo').textbox("setValue", datas.dtSpec[0].ContainerNo);
            //如果存在提起记录
            if (!isNullOrWhiteSpaceStr(datas.productDt[0].QUALITYHISTORYRECORDID)) {
                $('#UnqualifiedForm').form('load', { UnqualifiedDescribe: datas.productDt[0].UNQUALIFIEDDESCRIBE, IsKeyFeatures: datas.productDt[0].ISKEYFEATURES, IsImportantFeatures: datas.productDt[0].ISIMPORTANTFEATURES, IsDesignBasisFeatures: datas.productDt[0].ISDESIGNBASISFEATURES });
            }
            //绑定工厂下拉框
            $("#selFactory").combobox({
                valueField: 'FACTORYID',
                textField: 'FACTORYNAME',
                panelHeight: 200,
                data: datas.dtFactory, //下拉数据
                value: datas.productDt[0].FACTORYID, //分厂默认值
                onSelect: function (record) {
                    page.bindEmployee(record.FACTORYID, datas.productDt[0].DUTYEMPLOYEEID); //加载责任人
                }
            });
        });
    },
    //动态获取责任人(分厂ID,默认值)
    bindEmployee: function (factoryID, defultValue) {
        if (factoryID === "") {
            displayMessage("未选择责任分厂", false);
            return;
        }
        page.post(page.url, { action: "GetEmployee", factoryID: factoryID }, true, function (res) {
            if (!res.Result) {
                displayMessage(res.Message, false);
                return;
            }
            //绑定责任人下拉框
            $("#selDutyemployee").combobox({
                valueField: 'EMPLOYEEID',
                textField: 'FULLNAME',
                panelHeight: 200,
                data: res.DBTable, //下拉数据
                value: defultValue,
                editable: true,
                filter: function (q, row) { //可模糊搜索
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) > -1;
                }
            });
        });
    },
    //保存数据
    saveData: function () {
        $('#btnSure').linkbutton('disable'); //禁用按钮
        var formData = {};
        formData["QualityHistoryRecordID"] = $('#QualityHistoryRecordID').val(); //质量提起ID
        formData["productname"] = $('#ProductName').textbox('getValue'); //零件号
        formData["workflowStepID"] = $('#WorkflowStepID').val(); //工序ID
        formData["togetherflag"] = $('#TogatherFlag').textbox('getValue'); //大批次
        formData["mfgOrderName"] = $('#MfgOrderName').textbox('getValue'); //订单号
        formData["containerNo"] = $('#ContainerNo').textbox('getValue'); //零件批次号
        formData["CheckNO"] = $('#CheckNO').textbox('getValue'); //检验编号
        formData["Partcategory"] = $('#Partcategory').textbox('getValue'); //零件类别
        formData["DutyEmployeeID"] = $('#selDutyemployee').combobox('getValue'); //责任者ID
        formData["UnqualifiedNum"] = $('#UnqualifiedNum').numberbox('getValue'); //不合格品数
        formData["UnqualifiedDescribe"] = $('#UnqualifiedDescribe').textbox('getValue'); //不合格描述
        formData["FactoryID"] = $('#selFactory').combobox('getValue'); //责任单位ID
        formData["IsKeyFeatures"] = $("input[name='IsKeyFeatures']:checked").val(); //是否有关键特性超差
        formData["IsImportantFeatures"] = $("input[name='IsImportantFeatures']:checked").val(); //是否有重要特性超差
        formData["IsDesignBasisFeatures"] = $("input[name='IsDesignBasisFeatures']:checked").val(); //是否有设计基准要素超差
        if (isNullOrWhiteSpaceStr(formData.UnqualifiedNum)) {
            displayMessage2("不合格品数不能为空", false, ["btnSure"]);
            return;
        }
        if (isNullOrWhiteSpaceStr(formData.productname)) {
            displayMessage2("零件图号不能为空", false, ["btnSure"]);
            return;
        }
        if (isNullOrWhiteSpaceStr(formData.FactoryID)) {
            displayMessage2("责任单位不能为空", false, ["btnSure"]);
            return;
        }
        if (isNullOrWhiteSpaceStr(formData.DutyEmployeeID)) {
            displayMessage2("责任者不能为空", false, ["btnSure"]);
            return;
        }
        var param = {
            action: "SaveQulityCollectData",
            data: JSON.stringify([formData])
        };
        page.post(page.url, param, true, function (res) {
            displayMessage2(res.Message, res.Result, ["btnSure"]);
        });
    },
    //post数据（路径，参数，是否异步，成功返回方法）
    post: function (url, param, async, callback) {
        $.ajax({
            type: "Post",
            url: url,
            data: param,
            cashe: false,
            async: async,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
                $("body").find(".easyui-linkbutton").each(function () {
                    $(this).linkbutton('enable');
                });
            }
        });
    }
}
page.init();